//
//  HomeViewController.m
//  OurMenu
//
//  Created by 尹坤 on 15/10/9.
//  Copyright © 2015年 尹坤. All rights reserved.
//

#import "HomeViewController.h"
#import "WaterLayout.h"
#import "ShopMode.h"
#import "ShopCell.h"
#import "MJExtension.h"
#import "MiddleController.h"
#import "BottomViewController.h"
#import "MainViewController.h"
#import "iCarousel.h"
#import "CreatMIddleView.h"
#import "CreatBottomView.h"
#import "MainViewController.h"
@interface HomeViewController ()<iCarouselDataSource,iCarouselDelegate>


@end


@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"首页";
    

    
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scrollView.contentSize = CGSizeMake(0, 1175 );
    scrollView.backgroundColor = [UIColor colorWithRed:236/255.0 green:238/255.0 blue:234/255.0 alpha:1];
    //scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
    //顶部轮播图
    car = [[iCarousel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
    //car.backgroundColor = [UIColor yellowColor];
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:car.frame];
    imageview.image = [UIImage imageNamed:@"xican"];
    imageview.userInteractionEnabled = YES;
    [scrollView addSubview:imageview];
    [imageview addSubview:car];
    car.delegate = self;
    car.dataSource = self;
    car.type = 6;

    [self setMyView];
    
}
- (void)setMyView
{
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, car.frame.size.height, self.view.frame.size.width, 50)];
    topView.backgroundColor = [UIColor colorWithRed:200/255.0 green:71/255.0 blue:50/255.0 alpha:0.85];
    topView.layer.masksToBounds = YES;
    //topView.layer.cornerRadius = 10;
    [scrollView addSubview:topView];
    UIImageView *topimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    topimage.image = [UIImage imageNamed:@"bbe4ba55a8164854ce50ff2440bf437b"];
    //[topView addSubview:topimage];
   // topView.alpha = 0.4;
//    UIImageView *topImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, car.frame.size.height, self.view.frame.size.width, 50)];
//    topImage.image = [UIImage imageNamed:@"labelImage.jpg"];
//    [self.view addSubview:topImage];
    UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 40)];
    topLabel.text = @"一日三餐+甜点";
    [topView addSubview:topLabel];
    
    
    //创建一日三餐
    CreatMIddleView *myView = [[CreatMIddleView alloc] initWithFrame:CGRectMake(0, topView.frame.size.height + topView.frame.origin.y, self.view.frame.size.width, 150)];
    myView.backgroundColor = [UIColor colorWithRed:236/255.0 green:238/255.0 blue:234/255.0 alpha:1];
   // myView.layer.cornerRadius = 10;
    myView.layer.masksToBounds = YES;
    [scrollView addSubview:myView];
    
    //给一日三餐四个button点击点击方法
    [myView.breakfirstButton setImage:[UIImage imageNamed:@"zaocan"] forState:UIControlStateNormal];
    [myView.breakfirstButton addTarget:self action:@selector(breakfirst) forControlEvents:UIControlEventTouchUpInside];
    [myView.lunchButton setImage:[UIImage imageNamed:@"wucan"] forState:UIControlStateNormal];
    [myView.lunchButton addTarget:self action:@selector(lunch) forControlEvents:UIControlEventTouchUpInside];
    [myView.dinnerButton setImage:[UIImage imageNamed:@"wancan"] forState:UIControlStateNormal];
    [myView.dinnerButton addTarget:self action:@selector(dinner) forControlEvents:UIControlEventTouchUpInside];
    [myView.dessertButton setImage:[UIImage imageNamed:@"tiandian"] forState:UIControlStateNormal];
    [myView.dessertButton addTarget:self action:@selector(dessert) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *topView1 = [[UIView alloc] initWithFrame:CGRectMake(0, myView.frame.origin.y + myView.frame.size.height, self.view.frame.size.width, 50)];
    
    topView1.backgroundColor = [UIColor colorWithRed:200/255.0 green:71/255.0 blue:50/255.0 alpha:0.85];
    topView1.layer.masksToBounds = YES;
    //topView1.layer.cornerRadius = 10;
    [scrollView addSubview:topView1];
    UIImageView *topimage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    topimage1.image = [UIImage imageNamed:@"bbe4ba55a8164854ce50ff2440bf437b"];
    //[topView1 addSubview:topimage1];
    //topView1.alpha = 0.4;
    //    UIImageView *topImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, car.frame.size.height, self.view.frame.size.width, 50)];
    //    topImage.image = [UIImage imageNamed:@"labelImage.jpg"];
    //    [self.view addSubview:topImage];
    UILabel *topLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 100, 40)];
    topLabel1.text = @"四季流行菜";
    [topView1 addSubview:topLabel1];

    //创建四季流行餐
    
    CreatBottomView *myBottomView = [[CreatBottomView alloc] initWithFrame:CGRectMake(0,topView1.frame.origin.y + topView1.frame.size.height, self.view.frame.size.width, 150)];
    [myBottomView.seasonButton setImage:[UIImage imageNamed:@"chun"] forState:UIControlStateNormal];
    myBottomView.layer.cornerRadius = 10;
    myBottomView.layer.masksToBounds = YES;
    
    [myBottomView.seasonButton addTarget:self action:@selector(spring) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:myBottomView];
    
    CreatBottomView *myBottomView1 = [[CreatBottomView alloc] initWithFrame:CGRectMake(0, myBottomView.frame.origin.y + myBottomView.frame.size.height, self.view.frame.size.width, 150)];
    [myBottomView1.seasonButton setImage:[UIImage imageNamed:@"xia"] forState:UIControlStateNormal];
    myBottomView1.layer.cornerRadius = 10;
    myBottomView1.layer.masksToBounds = YES;
    myBottomView1.seasonLabel.text = @"     夏季";
    [myBottomView1.seasonButton addTarget:self action:@selector(summer) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:myBottomView1];
    
    CreatBottomView *myBottomView2 = [[CreatBottomView alloc] initWithFrame:CGRectMake(0, myBottomView1.frame.origin.y + myBottomView1.frame.size.height, self.view.frame.size.width, 150)];
    [myBottomView2.seasonButton setImage:[UIImage imageNamed:@"qiu"] forState:UIControlStateNormal];
    
    myBottomView2.layer.cornerRadius = 10;
    myBottomView2.layer.masksToBounds = YES;
    myBottomView2.seasonLabel.text = @"     秋季";
    [myBottomView2.seasonButton addTarget:self action:@selector(autumn) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:myBottomView2];
    
    myBottomView3 = [[CreatBottomView alloc] initWithFrame:CGRectMake(0, myBottomView2.frame.origin.y + myBottomView2.frame.size.height, self.view.frame.size.width, 150)];
    [myBottomView3.seasonButton setImage:[UIImage imageNamed:@"dong"] forState:UIControlStateNormal];
    myBottomView3.layer.cornerRadius = 10;
    myBottomView3.layer.masksToBounds = YES;
    myBottomView3.seasonLabel.text = @"     冬季";
    [myBottomView3.seasonButton addTarget:self action:@selector(winter) forControlEvents:UIControlEventTouchUpInside];
    [scrollView addSubview:myBottomView3];
    
    
    
    
}
//====一日三餐跳转
- (void)breakfirst
{
    MiddleController *midd = [[MiddleController alloc] init];
    midd.str = @"早餐";
    [self.navigationController pushViewController:midd animated:YES];
}
- (void)lunch
{
    MiddleController *midd = [[MiddleController alloc] init];
    midd.str = @"午餐";
    [self.navigationController pushViewController:midd animated:YES];
}
- (void)dinner
{
    MiddleController *midd = [[MiddleController alloc] init];
    midd.str = @"米饭";
    [self.navigationController pushViewController:midd animated:YES];
}
- (void)dessert
{
    MiddleController *midd = [[MiddleController alloc] init];
    midd.str = @"甜点";
    [self.navigationController pushViewController:midd animated:YES];
}
//==========
//四季流行菜谱跳转
- (void)spring
{
    BottomViewController *bottom = [[BottomViewController alloc] init];
    bottom.str = @"春季";
    [self.navigationController pushViewController:bottom animated:YES];
}
- (void)summer
{
    BottomViewController *bottom = [[BottomViewController alloc] init];
    bottom.str = @"夏季";
    [self.navigationController pushViewController:bottom animated:YES];
}
- (void)autumn
{
    BottomViewController *bottom = [[BottomViewController alloc] init];
    bottom.str = @"秋季";
    [self.navigationController pushViewController:bottom animated:YES];
}
- (void)winter
{
    BottomViewController *bottom = [[BottomViewController alloc] init];
    bottom.str  = @"冬季";
    [self.navigationController pushViewController:bottom animated:YES];
}


#pragma mark -- 轮播图的代理方法
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    //图片的个数
    return 9;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
    //NSLog(@"%lu",(unsigned long)index);
    UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%ld",index+1]]];
    view.backgroundColor = [UIColor greenColor];
    view.layer.cornerRadius = 10;
    view.layer.masksToBounds = YES;
    //图片的宽高
    view.frame = CGRectMake(0, 20, 180, 260);
    //view.tag = index;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = view.frame;
    button.tag = index;
    [button addTarget:self action:@selector(touchme:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    return view;
}

- (void)touchme:(UIButton *)but
{
    //NSLog(@"%ld",but.tag);
    MainViewController *main = [[MainViewController alloc] init];
    if (but.tag == 0) {
        main.str = @"家常菜";
    }else if (but.tag == 1){
        main.str = @"快手菜";
    }else if (but.tag == 2){
        main.str = @"创意";
    }else if (but.tag == 3){
        main.str = @"烤";
    }else if (but.tag == 4){
        main.str = @"凉菜";
    }else if (but.tag == 5){
        main.str = @"面食";
    }else if (but.tag == 6){
        main.str = @"素菜";
    }else if (but.tag == 7){
        main.str = @"汤";
    }else if (but.tag == 8){
        main.str = @"料";
    }
    [self.navigationController pushViewController:main animated:YES];
}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
    //图片之间的距离
    return 250;
}

- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset
{
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0);
    
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = car.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);
    return CATransform3DTranslate(transform, 0.0, 0.0, offset * car.itemWidth);
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return YES;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
